//
//  ReserverInfoPriceCell.swift
//  koolcar
//
//  Created by xiantian on 2023/11/29.
//

import UIKit

class ReserverInfoPriceCell: UITableViewCell {
    var tipLab: UILabel!
    var totalPriceLab: UILabel!
    var seaCarFalg: Bool = false
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        tipLab = UILabel()
        tipLab.textColor = Theme.titleLabColor
        tipLab.backgroundColor = UIColor.clear
        tipLab.font = UIFont.init(name: Theme.PingFangSCMedium, size: 16)
        tipLab.numberOfLines = 1
        tipLab.lineBreakMode = .byTruncatingTail
        tipLab.textAlignment = .center
        tipLab.text = MMLocalizedString("booking_payment", comment: "预订支付")
        contentView.addSubview(tipLab)
        
        totalPriceLab = UILabel()
        totalPriceLab.textColor = Theme.titleLabColor
        totalPriceLab.backgroundColor = UIColor.clear
        totalPriceLab.font = UIFont.init(name: Theme.PingFangSCMedium, size: 16)
        totalPriceLab.numberOfLines = 1
        totalPriceLab.lineBreakMode = .byTruncatingTail
        totalPriceLab.textAlignment = .center
        //totalPriceLab.text = ""
        contentView.addSubview(totalPriceLab)
        
        self.addSnpLayout()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func addSnpLayout(){
        tipLab.snp.makeConstraints { make in
            make.top.equalTo(40)
            make.left.equalTo(14)
            make.right.equalTo(-14)
            make.height.greaterThanOrEqualTo(30)
        }
        
        totalPriceLab.snp.makeConstraints { make in
            make.left.equalTo(14)
            make.right.equalTo(-14)
            make.top.equalTo(tipLab.snp.bottom)
            make.height.greaterThanOrEqualTo(30)
            make.bottom.equalTo(0)
        }
    }
    
    
    //setModel
    func setReserverInfoPriceCell(model: CarDetailsContentModel? = nil){
        self.tipLab.text = MMLocalizedString("booking_payment", comment: "预订支付")
        
        var orderPrice = ""
        if self.seaCarFalg {
            orderPrice = XTManageCenter.showPriceInComma(source: (model?.subscription ?? 0).cleanZero)
        }else{
            orderPrice = XTManageCenter.showPriceInComma(source: (model?.orderPrice ?? 0).cleanZero)
        }
        self.totalPriceLab.text = XTManageCenter.currentSign() + orderPrice
        self.updateConstraints()
    }
    
}
